#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		int f = 0, pos = -1;
		for (int i = 1; i <= n; i++)
		{
			if (i * (i - 1) / 2 + (n - i)*(n - i - 1) / 2 == k)
			{
				f = 1;
				pos = i;
				break;
			}
		}
		if (f)
		{
			cout << "YES" << endl;
			for (int i = 1; i <= pos; i++)
				cout << 1 << " ";
			for (int i = pos + 1; i <= n; i++)
				cout << -1 << " ";
			cout << endl;
		}
		else
			cout << "NO" << endl;
	}
	return 0;
}